package com.fun.wyunfei.timeline;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.fun.wyunfei.timeline.bean.Article;
import com.fun.wyunfei.timeline.service.DbService;
import com.fun.wyunfei.timeline.util.DateUtil;

public class ArticleActivity extends FragmentActivity {

    private EditText article_title;
    private EditText article_content;
    private EditText article_other;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_article);
        initStateBar();
        article_title = findViewById(R.id.article_title);
        article_content = findViewById(R.id.article_content);
        article_other = findViewById(R.id.article_other);
        Button button = findViewById(R.id.button);
        button.setOnClickListener(this::onClick);


    }

    private void onClick(View view) {
        DbService dbService = new DbService(getApplicationContext());
        Article article = new Article();
        article.setDate(DateUtil.getDateWithMinute());
        article.setTitle(article_title.getText().toString());
        article.setContent(article_content.getText().toString());
        article.setOther(article_other.getText().toString());
        dbService.insert(article);
        Toast.makeText(getApplicationContext(), "OK", Toast.LENGTH_SHORT).show();
    }

    private void initStateBar() {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
    }
}
